package com.ihr360.payroll.model.dto.attendance.rule.overtime;

import com.ihr360.commons.model.type.WorkHourType;
import com.ihr360.payroll.model.dto.attendance.supperclass.AbstractCalcAttendanceRule;
import lombok.Data;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToOne;

/**
 * 加班规则
 */
@Entity
@Data
public class OvertimeRule extends AbstractCalcAttendanceRule {
    /**
     * 周末比例
     */
    @Column(length = 8)
    private Double weekendRatio;

    /**
     * 节假日比例
     */
    @Column(length = 8)
    private Double holidayRatio;

    /**
     * 综合工时
     */
    @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "rule")
    private SyntheticalOverTimeRule rule;

    public WorkHourType getWorkHourType() {
        boolean standard = !this.getReferenceFields().isEmpty() || this.getFixedBase() != null;
        boolean synthetical = rule != null;
        if (standard && synthetical) {
            return WorkHourType.ALL;
        } else if (standard && !synthetical) {
            return WorkHourType.STANDARD;
        } else if (!standard && synthetical) {
            return WorkHourType.SYNTHETICAL;
        } else {
            return null;
        }
    }
}